#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

int maxProfit(int* prices, int pricesSize)
{
    int ret = 0;
    int right = 1;
    int left = 0;
    int esc = pricesSize - 1;
    while (right <= esc)
    {
        int mid = prices[right] - prices[left];
        ret = mid > ret ? mid : ret;
        if (mid < 0)
            left = right;
        right++;
    }
    return ret;
}